var MaterialClassifyModel = function (data) {
  BaseModel.call(this);

  var self = this;
  var fn = {
    initData: function (data) {
      if (data === undefined) {
        data = {
          status: 1
        };
      } else {
        self.id = data.id;
      }

      var classifyLevel = MaterialClassifyModel.classifyLevel;
      for (var i = 0; i < classifyLevel.length; i++) {
        var field = classifyLevel[i];
        var value = data[field];
        if (SysUtil.isEmpty(value)) {
          value = '';
        }
        self[field] = value;
      }
      self.status = data.status;
    }
  };

  this.checkValid = function () {
    if (this.levelRankOne.trim() === '') {
      return 'levelRankOne';
    }

    var classifyLevel = MaterialClassifyModel.classifyLevel;
    var nameList = [];
    var dataList = [],
      noDataList = [];
    for (var i = 0; i < classifyLevel.length; i++) {
      var field = classifyLevel[i];
      var value = this[field].trim();
      if (value === '') {
        noDataList.push(i);
      } else {
        dataList.push(i);
        nameList.push(value);
      }
    }
    var hasDataIndex = dataList[dataList.length - 1];
    var noDataIndex = noDataList[0];
    if (noDataIndex < hasDataIndex) {
      return classifyLevel[noDataIndex];
    }

    var list = _.uniq(nameList);
    if (list.length !== nameList.length) {
      return 'repeat';
    }
    return '';
  };

  this.getObject = function(){
    var postData = {
      stauts:this.status
    };
    var id = this.id;
    if (!SysUtil.isEmpty(id)) {
      postData.id = id;
    }

    var classifyLevel = MaterialClassifyModel.classifyLevel;
    for (var i = 0; i < classifyLevel.length; i++) {
      var field = classifyLevel[i];
      var value = this[field];
      postData[field] = value;
    }
    return postData;
  };

  fn.initData(data);
};

MaterialClassifyModel.classifyLevel = [
  'levelRankOne',
  'levelRankTwo',
  'levelRankThree',
  'levelRankFour',
  'levelRankFive',
  'levelRankSix',
  'levelRankSeven',
  'levelRankEight',
  'levelRankNine',
  'levelRankTen'
];
